package example;

class Test {
    public  int count = 0;
    public  void add(){
        count++;
    }
}
public class Example2 {
    public static void main(String[] args) throws InterruptedException {
        Test test = new Test();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                   test.add();
                }
            }
        };

        Thread  t2 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    test.add();
                }
            }
        };
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(test.count);
    }
}
